package cn.platform.task;

import cn.platform.mapper.AttendanceMapper;
import cn.platform.service.AttendanceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

@Slf4j
@Component
public class AttendanceCleanupTask {
    @Autowired
    private AttendanceService attendanceService;
    @Autowired
    private AttendanceMapper attendanceMapper;

    @Scheduled(cron = "0 0 1 * * ?")
    public void deleteOldAttendanceRecords(){
        LocalDateTime oneMonthAgo = LocalDate.now().minusMonths(1).atStartOfDay();
        log.info("定时任务启动：删除{}之前的考勤记录",oneMonthAgo);
        int deleted = attendanceMapper.deleteBeforeTime(oneMonthAgo);
        log.info("定时任务完成：共删除{}条考勤记录",deleted);
    }

}
